package com.tour.tour.controller;

import com.tour.tour.common.Response;
import com.tour.tour.dto.TourRouteDTO;
import com.tour.tour.exception.AuthorizationForbiddenException;
import com.tour.tour.exception.UserStatusException;
import com.tour.tour.service.TourRouteService;
import com.tour.tour.vo.TourRouteVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 76004
 * @apiNote
 * @date 2023/4/27 20:36
 */
@RestController
@RequestMapping("/route")
@CrossOrigin
public class TourRouteController {
    @Autowired
    private TourRouteService tourRouteService;

    @GetMapping("/selectPage")
    public Response<List<TourRouteVO>>selectPage(Integer pageNum, Integer pageSize) throws UserStatusException {
        return tourRouteService.getPage(pageNum,pageSize);
    }

    @DeleteMapping("/delete")
    public Response<Void> delete(Long tid, HttpServletRequest httpServletRequest) throws UserStatusException, AuthorizationForbiddenException {
        return tourRouteService.delete(tid,httpServletRequest);
    }

    @PostMapping("/add")
    public Response<Void> add(@RequestBody TourRouteDTO tourRouteDTO, HttpServletRequest httpServletRequest) throws UserStatusException, AuthorizationForbiddenException {
        return tourRouteService.addTourRoute(tourRouteDTO,httpServletRequest);
    }

    @PutMapping("/update")
    public Response<Void> update(@RequestBody TourRouteDTO tourRouteDTO,HttpServletRequest httpServletRequest) throws UserStatusException, AuthorizationForbiddenException {
        return tourRouteService.addTourRoute(tourRouteDTO,httpServletRequest);
    }

}
